<?php

// This file keeps track of upgrades to
// the numerical qtype plugin
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installation to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.

function xmldb_qtype_autofeedback_upgrade($oldversion) {
global $CFG, $DB;

    $dbman = $DB->get_manager();
	if ($oldversion < 2011050803) {
		
		
		// Define table autofeedback_lexemes to be created
        $table = new xmldb_table('autofeedback_lexemes');

        // Adding fields to table autofeedback_lexemes
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('answerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
        $table->add_field('text', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('serialnumber', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'generic');

        // Adding keys to table autofeedback_lexemes
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('answerid', XMLDB_KEY_FOREIGN, array('answerid'), 'question_answers', array('id'));

        // Conditionally launch create table for autofeedback_lexemes
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // autofeedback savepoint reached
        upgrade_plugin_savepoint(true, 2011050803, 'qtype', 'autofeedback');
	}
}